package com.humanminoritygame.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.humanminoritygame.model.CategoryRepo;
import com.humanminoritygame.model.QuestionRepo;
import com.humanminoritygame.model.Room;
import com.humanminoritygame.model.Subscription;
import com.humanminoritygame.model.SubscriptionRepo;
import com.humanminoritygame.model.UserRepo;

@Controller
public class RankingController {

  SubscriptionRepo subsciptions;
  QuestionRepo questions;
  CategoryRepo categories;
  UserRepo users;
  
  
  @Autowired
  public RankingController(SubscriptionRepo subscriptions, QuestionRepo questions, CategoryRepo categories, UserRepo users){
    this.users = users;
    this.subsciptions = subscriptions;
    this.questions = questions;
    this.categories = categories;
  }
  
  
  @RequestMapping(method = RequestMethod.GET)
  public ModelAndView bySubscription(@RequestParam("id") Long subscriptionId){
    ModelAndView mav = new ModelAndView();
    mav.setViewName("rankingBySubscription");
    
    Subscription subscription = subsciptions.getSubscription(subscriptionId); 
    Room room = subscription.getRoom();
    mav.addObject("category", room.getCategory());
    mav.addObject("subscriptions", subsciptions.getRoomActiveSubscriptions(room));
    mav.addObject("roomState", room.getState());
    
    return mav;
  }
 
  
  
}
